<template>
  <div>
    <ul>
      <li v-for="(item,index) in arr" :key="index">
        {{item}} <button @click="remove(index)">删除</button>
      </li>
    </ul>
    <button @click.prevent="random">生成随机数</button>
  </div>
</template>

<script>
export default {
  data(){
    return{
      arr:[2,1,9]
    }
  },
  methods:{
    random(){
      this.arr.push(Math.floor(Math.random()*10))
    },
    remove(index){
      this.arr.splice(index,1)
    }
  }
}
</script>

<style>

</style>